package com.topscore.uke.mvp.model;

import com.topscore.uke.entities.AddressListItem;
import com.topscore.uke.mvp.contractors.GetMemberAddressListContractor;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.network.retrofit.HandleErrorSubscriber;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 71468 on 2017/10/19.
 */

public class GetMemberAddressListModel implements GetMemberAddressListContractor, GetMemberAddressListContractor.Model {
    private String mPhone;

    public GetMemberAddressListModel(String phone) {
        this.mPhone = phone;
    }


    @Override
    public void getAddresses(Listener listener) {
        mService.getMemberAddressList(mPhone)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<List<AddressListItem>>>(listener) {
                    @Override
                    public void onSuccess(BaseResponse<List<AddressListItem>> response) {
                        listener.onGetListSuccess(response);
                    }
                });
    }
}
